package fileoperator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileScanner {
	static List<String> dirs = new ArrayList<>();
	static List<String> files = new ArrayList<>();
	public static void main(String[] args) {
		String path = "E:/liutao_20170612_workspace/PINGANJK/src";
		getDirectory(new File(path));
		listFile("java");
		//dirs.forEach(dir ->{System.out.println(dir);});
		//System.out.println(dirs);
		files.forEach(fileName -> {System.out.println(fileName);});
		
	}
	
	/**@param string 结尾的文件
	 * */
	private static void listFile(String string) {
		dirs.forEach(dir -> {
			File file = new File(dir);
			file.listFiles(f ->{
				String fileName = f.getName();
				if(f.isFile() && fileName.endsWith(string)) {
					files.add(fileName);
				}
				return false;
			});
		});
	}


	/**@param file 下的所有文件夹
	 * */
	public static void getDirectory(File file){
		if(file.isDirectory()) {
			dirs.add(file.getAbsolutePath());
			file.listFiles(item ->{
				if(item.isDirectory()) {
					getDirectory(item);
				}
				return false;
			});
		}
	}
}
